﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeChat.Common;
using WeChat.JsSDK.lib;
using BLL;
using WeChat.Common2;

namespace WeChat.JsSDK.WxPayTest
{
    public partial class TestWxPay : System.Web.UI.Page
    {
        //public static string openid;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //认证后得到code值
                if (Request.QueryString["code"] != null || Request.QueryString["code"] != "")
                {
                    string code = Request.QueryString["code"];
                    ApplicationLog.Write("code:" + code);
                    Session["openid"] = OAuthHelper.getOpenid(code);
                    string openid = Session["openid"].ToString();
                    ApplicationLog.Write("获取到的openid:" + openid);
                    if (!new BindIdBLL().verifyId(openid))//验证是否绑定账号
                    {
                        Response.Redirect("/Binding.aspx");
                    }
                }
            }

        }
        //提交支付
        protected void btn1_Click(object sender, EventArgs e)
        {
            string openid = Session["openid"].ToString();
            string total_fee = Request["selVal"].ToString();

            string url = "http://" + Config.domainName + "/JsSDK/WxPayTest/WxPay.aspx?openid=" + openid + "&total_fee=" + total_fee;
            ApplicationLog.Write("支付下单提交跳转url:" + url);
            Response.Redirect(url);
        }

        //public string getPayJson()
        //{
        //    //string total_fee = (Request["selVal"] ?? string.Empty);
        //    string total_fee = selVal.Value;
        //    wxJsApiParam = WxPayApi.getPayJson(openid, total_fee);
        //    return wxJsApiParam;
        //}

        
        
    }
}
